home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- //////////////////////////////////////////////////////////////////////
- // Road.c++ - implementation of the road class
- //////////////////////////////////////////////////////////////////////
-
- #include "Road.h"
- #include "Stretch.h"
- #include "Straight.h"
- #include "Curve.h"
- #include "Connect.h"
-
-
- Road::Road(SbString filename)
- {
- // XXX determine from -metric
- _distance_factor = 5280.0;
-
- // read the road file
-
- FILE *road_file = fopen(filename.getString(), "r");
-
- if (! road_file)
- {
- fprintf(stderr, "Road: Could not open road file %s\n",filename.getString());
- exit(-1);
- }
-
- int start_stretch_num;
-
- fscanf(road_file,"%d %d", &_num_stretches, &start_stretch_num);
-
- if ((_num_stretches + 1) > MAX_STRETCHES)
- {
- fprintf(stderr, "\nRoad: Too many stretches.\n");
- exit(1);
- }
-
- // the zeroth stretch is the null stretch
- _stretch[0] = NULL;
-
- float width;
- fscanf(road_file,"%f", &width);
-
- for (int i = 0; i < _num_stretches; i++)
- {
- int stretch_num, prev, next;
- float length = 0.0, radius = 0.0, angle = 0.0, loop_offset = 0.0;
-
- char buf[24];
- fscanf(road_file,"%d %s %d %d",&stretch_num,buf,&prev,&next);
- SbString stretch_type(buf);
-
- if (stretch_type == "curve")
- {
- fscanf(road_file,"%f %f", &radius, &angle);
-
- _stretch[stretch_num] =
- new Curve(_stretch[prev],_stretch[next],radius,width,angle);
- }
- else if (stretch_type == "straight")
- {
- fscanf(road_file,"%f %f", &length, &angle);
-
- _stretch[stretch_num] =
- new Straight(_stretch[prev],_stretch[next],length,width,angle);
- }
- else if (stretch_type == "loop")
- {
- fscanf(road_file,"%f %f", &length, &loop_offset);
-
- _stretch[stretch_num] = new Straight(
- _stretch[prev],_stretch[next],length,width,360.0,0.0,loop_offset);
- }
- else if (stretch_type == "connect")
- {
- fscanf(road_file,"%f %f", &length, &angle);
-
- _stretch[stretch_num] =
- new Connect(_stretch[prev],_stretch[next]);
- }
- else
- {
- fprintf(stderr,
- "Road: unknown stretch type: %s\n",stretch_type.getString());
-
- exit(-1);
- }
- }
-
- fclose(road_file);
-
- _start = _stretch[start_stretch_num];
- }
-
-
- Road::~Road()
- {
- for (int i = 0; i <= _num_stretches; i++)
- delete _stretch[i];
- }
-
-
- void Road::draw(
- const Stretch *stretch, int marker, int display_mode,
- Car *ignore_car)
- {
- if (stretch)
- {
- stretch->init_draw(); // initialize culling
- stretch->draw(marker, display_mode, ignore_car);
- }
- else
- {
- fprintf(stderr,"\nRoad: Null roadway\n");
- exit(-1);
- }
- }
-